package com.hc.excel.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.hc.comm.CommData;


public class CreateDownFileTestExcelToDisk {

	public static boolean CreateDownFileTestExcel(List data,String filePath,String startDate,String stopDate){

		// TODO Auto-generated method stub
		try {
			InputStream in = new FileInputStream(CommData.systemPath+"ExcelFile\\downFileTest.xls");
			Workbook work = new HSSFWorkbook(in);
			// 得到excel的第0张表
			Sheet sheet = work.getSheetAt(0);
			// 得到第1行的第一个单元格的样式
			Row rowCellStyle = sheet.getRow(1);
			CellStyle columnOne = rowCellStyle.getCell(0).getCellStyle();
			// 这里面的行和列的数法与计算机里的一样，从0开始是第一
			// 填充title数据
			Row row = null;
		
//			cell.setCellValue("2010年花名测");

	
//			int len = 11+data.size();
			// 得到行，并填充数据和表格样式
			for (int i = 0;i < data.size(); i++) {
				
				row = sheet.createRow((int) i+11);
				Map map = (Map) data.get(i);
				// 第四步，创建单元格，并设置值
				row.createCell((short) 0).setCellValue(map.get("userNumber").toString());
				row.createCell((short) 1).setCellValue(map.get("intranetIp").toString());
				row.createCell((short) 2).setCellValue(map.get("externalIp").toString());
				row.createCell((short) 3).setCellValue(map.get("bSize").toString());
				row.createCell((short) 4).setCellValue(map.get("vlanId1").toString());
				row.createCell((short) 5).setCellValue(map.get("vlanId2").toString());
				row.createCell((short) 6).setCellValue(map.get("speedMax").toString());
				row.createCell((short) 7).setCellValue(map.get("speedAvr").toString());
				row.createCell((short) 8).setCellValue(map.get("speedMin").toString());
				row.createCell((short) 9).setCellValue(map.get("cmdTime").toString());
		
				
				
//				row = sheet.createRow(i);// 得到行
//				cell = row.createCell(0);// 得到第0个单元格
//				cell.setCellValue("琳"+i);// 填充值
//				cell.setCellStyle(columnOne);// 填充样式
//				cell = row.createCell(1);
//				cell.setCellValue("女");
//				cell.setCellStyle(columnOne);// 填充样式
//				cell = row.createCell(2);
//				cell.setCellValue(i+20);
//				cell.setCellStyle(columnOne);// 填充样式
			
			}
			//创建每个单元格，添加样式，最后合并
			row = sheet.getRow(5);
			
			Cell cell = row.getCell(1);
			cell.setCellValue(startDate);// 填充值
			
			
			row = sheet.getRow(6);
			 cell = row.getCell(1);
			cell.setCellValue(stopDate);// 填充值
			
			


			
			FileOutputStream os = new FileOutputStream(CommData.excelTempFilePath+"\\"+filePath+".xls");
			work.write(os);
			os.close();
		} catch (FileNotFoundException e) {
			System.out.println("文件路径错误");
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			System.out.println("文件输入流错误");
			e.printStackTrace();
			return false;
		}

	
		return true;
	}
	
}
